﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Drawing.Imaging;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos.mh_cauhinh
{
    public partial class mh_dm_mayin : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                this.tabHoaDon.Text = rm.GetString("inhoadon", culture);
                this.tabBep.Text = rm.GetString("inbep", culture);
                this.tabBienNhan.Text = rm.GetString("inbiennhan", culture);
                groupBox4.Text = rm.GetString("danhsachmayin", culture);
                gridColumn1.Caption = rm.GetString("POS", culture) + "#";
                gridColumn2.Caption = rm.GetString("Ten", culture);
                gridColumn3.Caption = rm.GetString("Com", culture);
                gridColumn4.Caption = rm.GetString("Bound", culture);
                gridColumn5.Caption = rm.GetString("Parity", culture);
                gridColumn6.Caption = rm.GetString("Data", culture);
                gridColumn7.Caption = rm.GetString("Stop", culture);
                gridColumn8.Caption = rm.GetString("Flow", culture);
                gridColumn18.Caption = rm.GetString("Timeout", culture);
                simpleButton2.Text= rm.GetString("them", culture);
                simpleButton7.Text= rm.GetString("sua", culture);
                simpleButton8.Text = rm.GetString("xoa", culture);
                groupBox3.Text = rm.GetString("cauhinh", culture);
                check_inlogo.Text = rm.GetString("inlogo", culture);
                lblHEADER.Text = rm.GetString("dautrang", culture);
                label8.Text = rm.GetString("diachi", culture);
                label7.Text= rm.GetString("tieude", culture);
                lblFOOTER.Text= rm.GetString("cuoitrang", culture);
                label9.Text = rm.GetString("dienthoai", culture);
                lblMARIN_TOP.Text= rm.GetString("canhtren", culture);
                lblMARIN_BOTTOM.Text= rm.GetString("canhduoi", culture);
                chkHD_PRINT_PRICE.Text= rm.GetString("ingia", culture);
                chkHD_PRINT_STORE_ADDRESS.Text = rm.GetString("indiachi", culture);
                chkHD_PRINT_STORE_NAME.Text= rm.GetString("intencuahieu", culture);
                chkHD_PRINT_RECEIPT_TITLE.Text= rm.GetString("intieude", culture);
                chkHD_PRINT_PHONE_NUMBER.Text= rm.GetString("indienthoai", culture);
                chkHD_PRINT_ORDER_NO.Text = rm.GetString("insohoadon", culture);
                btnLuu_BienNhan.Text = rm.GetString("luu", culture);
                btnThoat_HoaDon.Text = rm.GetString("thoat", culture);
                groupBox2.Text = rm.GetString("danhsachmayin", culture);
                btnCauHinh_Bep.Text  = rm.GetString("cauhinh", culture);
                simpleButton5.Text = rm.GetString("them", culture);
                simpleButton3.Text = rm.GetString("sua", culture);
                simpleButton4.Text = rm.GetString("xoa", culture);
                gridColumn9.Caption = rm.GetString("POS", culture) + "#";
                gridColumn10.Caption = rm.GetString("Ten", culture);
                gridColumn11.Caption = rm.GetString("Com", culture);
                gridColumn12.Caption = rm.GetString("Boud", culture);
                gridColumn13.Caption = rm.GetString("Parity", culture);
                gridColumn14.Caption = rm.GetString("Data", culture);
                gridColumn15.Caption = rm.GetString("Stop", culture);
                gridColumn16.Caption = rm.GetString("Flow", culture);
                gridColumn17.Caption = rm.GetString("Timeout", culture);
                groupBox7.Text = rm.GetString("thietlapmayinbep", culture);
                btnBep_Len.Text = rm.GetString("trangtren", culture);
                btnBep_Xuong.Text = rm.GetString("trangduoi", culture);
                btnBep_Luu.Text = rm.GetString("luu", culture);
                btnThoat_Bep.Text = rm.GetString("thoat", culture);
                gridColumn28.Caption = rm.GetString("nhomhang", culture);
                gridColumn29.Caption = rm.GetString("mon", culture);

                groupBox5.Text = rm.GetString("danhsachmayin", culture);
                gridColumn19.Caption = rm.GetString("POS", culture) + "#";
                gridColumn20.Caption = rm.GetString("Ten", culture);
                gridColumn21.Caption = rm.GetString("Com", culture);
                gridColumn22.Caption = rm.GetString("Bound", culture);
                gridColumn23.Caption = rm.GetString("Parity", culture);
                gridColumn24.Caption = rm.GetString("Data", culture);
                gridColumn25.Caption = rm.GetString("Stop", culture);
                gridColumn26.Caption = rm.GetString("Flow", culture);
                gridColumn27.Caption = rm.GetString("Timeout", culture);
                simpleButton6.Text = rm.GetString("them", culture);
                simpleButton9.Text = rm.GetString("sua", culture);
                simpleButton10.Text = rm.GetString("xoa", culture);
                groupBox6.Text = rm.GetString("cauhinh", culture);
                check_inlogo_BN.Text = rm.GetString("inlogo", culture);
                label4.Text = rm.GetString("dautrang", culture);
                label11.Text = rm.GetString("diachi", culture);
                label6.Text = rm.GetString("tieude", culture);
                label3.Text = rm.GetString("cuoitrang", culture);
                label10.Text = rm.GetString("dienthoai", culture);
                label2.Text = rm.GetString("canhtren", culture);
                label1.Text = rm.GetString("canhduoi", culture);
                chkBN_PRINT_PRICE.Text = rm.GetString("ingia", culture);
                chkBN_PRINT_STORE_NAME.Text = rm.GetString("intencuahieu", culture);
                chkBN_PRINT_RECEIPT_TITLE.Text = rm.GetString("intieude", culture); 
                chkBN_PRINT_STORE_ADDRESS.Text = rm.GetString("indiachi", culture);
                chkBN_PRINT_PHONE_NUMBER.Text = rm.GetString("indienthoai", culture);
                chkBN_PRINT_ORDER_NO.Text = rm.GetString("insohoadon", culture);
                simpleButton11.Text = rm.GetString("luu", culture);
                simpleButton1.Text = rm.GetString("thoat", culture);
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion
        public mh_dm_mayin()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }

        private void mh_dm_mayin_bep_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            this.showData_BEP_MayIn();
            //
            this.showData_HoaDon_MayIn();
            this.showData_HoaDon_CauHinh();
            //
            this.showData_BIENNHAN_MayIn();
            this.showData_BIENNHAN_CauHinh();
        }

        #region "   BEP"
        #region "   them - xoa - sua"
        private void simpleButton5_Click(object sender, EventArgs e)
        {
            //them            
            this.ShowEdit_BEP("-1");
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            ma = dr["DM_MAYIN_BEP_MA"] + "";

            if (ma != "") 
            {
                if (new mh_thongbao("Bạn muốn xóa", 3).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_BEP WHERE DM_MAYIN_BEP_MA=" + ma;
                    thuvien othuvien = new thuvien();
                    int irt = othuvien.SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });
                    string sSQL1 = "SELECT * FROM DM_HH dh WHERE dh.DM_MAYIN_BEP_MA ='ma'";
                    DataTable tbDM_HH = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL1 });
                    foreach (DataRow dr1 in tbDM_HH.Select())
                    {
                        sSQL = "UPDATE DM_HH SET DM_MAYIN_BEP_MA = NULL WHERE OBJID = '" + dr1["OBJID"] + "'";
                        othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
                    }
                    this.showData_BEP_MayIn();
                }
            }
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_Bep.GetDataRow(gridView_Bep.FocusedRowHandle);
            ma = dr["DM_MAYIN_BEP_MA"] + "";
            this.ShowEdit_BEP(ma);
        }
        #endregion

        void showData_BEP_MayIn()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BEP";

            DataTable tbInBep = othuvien.SP_SelectDataTable("SP_EXECUTESQL",
                                                            new string[] { "@sSQL" },
                                                            new object[] { sSQL });
            gridControl_Bep.DataSource = tbInBep.Copy();

            DataTable tbNHOMCHUHH = this.showData_BEP_MayIn_Loai();

            cbomayin1.Properties.Items.Clear();
            cbomayin2.Properties.Items.Clear();
            cbomayin3.Properties.Items.Clear();
            cbomayin4.Properties.Items.Clear();
            cbomayin5.Properties.Items.Clear();
            cbomayin6.Properties.Items.Clear();
            DataRow drTMP = tbInBep.NewRow();
            drTMP["OBJNAME"] = "(Chọn)";
            tbInBep.Rows.InsertAt(drTMP, 0);

            if (btn_bep1.Tag + "" != "0" && btn_bep1.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin1, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin1.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep1.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep1.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin1._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
            if (btn_bep2.Tag + "" != "0" && btn_bep2.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin2, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin2.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep2.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep2.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin2._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
            if (btn_bep3.Tag + "" != "0" && btn_bep3.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin3, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin3.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep3.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep3.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin3._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
            if (btn_bep4.Tag + "" != "0" && btn_bep4.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin4, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin4.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep4.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep4.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin4._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
            if (btn_bep5.Tag + "" != "0" && btn_bep5.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin5, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin5.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep5.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep5.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin5._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
            if (btn_bep6.Tag + "" != "0" && btn_bep6.Tag + "" != "")
            {
                othuvien.f_showdataoncombox(cbomayin6, tbInBep.Copy(), "DM_MAYIN_BEP_MA", "OBJNAME");
                cbomayin6.SelectedIndex = 0;
                if (tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep6.Tag + "'").Length == 1)
                {
                    string sDM_MAYIN_BEP_MA = tbNHOMCHUHH.Select("OBJID LIKE '" + btn_bep6.Tag + "'")[0]["DM_MAYIN_BEP_MA"] + "";
                    cbomayin6._SetselectedID(sDM_MAYIN_BEP_MA);
                }
            }
        }
        
        DataTable showData_BEP_MayIn_Loai()
        {
            int iLan = int.Parse(btn_bep6.Text) / 6;
            if (iLan < 1)
            {
                iLan = 1;
                return null;
            }
            string sSQL = "SELECT OBJID, OBJCODE, OBJNAME, GHICHU, DM_MAYIN_BEP_MA FROM DM_NHOMCHUHH";
            DataTable tbNHOMCHUHH = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", 
                                                                    new string[] { "@sSQL" }, 
                                                                    new object[] { sSQL });
            btn_bep1.Tag = 0;
            btn_bep2.Tag = 0;
            btn_bep3.Tag = 0;
            btn_bep4.Tag = 0;
            btn_bep5.Tag = 0;
            btn_bep6.Tag = 0;
            for (int i = 1; i <= tbNHOMCHUHH.Rows.Count; i++)
            {
                DataRow drTMP = tbNHOMCHUHH.Rows[i - 1];
                if (i == 1 + (iLan - 1) * 6)
                {
                    btn_bep1.Tag = drTMP["OBJID"] + "";
                }
                else if (i == 2 + (iLan - 1) * 6)
                {
                    btn_bep2.Tag = drTMP["OBJID"] + "";
                }
                else if (i == 3 + (iLan - 1) * 6)
                {
                    btn_bep3.Tag = drTMP["OBJID"] + "";
                }
                else if (i == 4 + (iLan - 1) * 6)
                {
                    btn_bep4.Tag = drTMP["OBJID"] + "";
                }
                else if (i == 5 + (iLan - 1) * 6)
                {
                    btn_bep5.Tag = drTMP["OBJID"] + "";
                }
                else if (i == 6 + (iLan - 1) * 6)
                {
                    btn_bep6.Tag = drTMP["OBJID"] + "";
                }
            }
            return tbNHOMCHUHH;
        }

        void ShowEdit_BEP(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_Bep, _ma);
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_BEP_MayIn();
        }

        private void btnThoat_Bep_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        

        private void btn_bep1_Click(object sender, EventArgs e)
        {
            DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
            string sTAG = btn.Tag + "";

            string sSQL = "SELECT OBJNAME1 = a.OBJNAME, OBJNAME2 = ISNULL(h.OBJNAME, h.SHORTNAME) " +
                          "FROM DM_NHOMCHUHH a " +
                          "     LEFT JOIN DM_NHOMHH b ON b.MANHOMCHU = a.OBJID " +
                          "	    LEFT JOIN DM_HH h ON b.OBJID = h.MANHOMHH " +
                          "WHERE A.OBJID LIKE '" + sTAG + "' " +
                          "ORDER BY a.OBJNAME, ISNULL(h.OBJNAME, h.SHORTNAME)";

            DataTable tbDM_HH = new thuvien().SP_SelectDataTable("SP_EXECUTESQL",
                                                                new string[] { "@sSQL" },
                                                                new object[] { sSQL });
            gridControl1.DataSource = tbDM_HH;

        }
        #region "   btnBep_Len Xuong_Click"
        private void btnBep_Len_Click(object sender, EventArgs e)
        {
            this.TangGiam_btnNUM(true);
        }

        private void btnBep_Xuong_Click(object sender, EventArgs e)
        {
            this.TangGiam_btnNUM(false);
        }
        void TangGiam_btnNUM(Boolean iTang)
        {
            int iSoHienTai = 0;
            int.TryParse(btn_bep1.Text, out iSoHienTai);
            if (iSoHienTai <= 1 && iTang)
                return;
            if (iTang)
                iSoHienTai = iSoHienTai - 6;
            else
                iSoHienTai = iSoHienTai + 6;

            btn_bep1.Text = iSoHienTai + "";
            btn_bep2.Text = ++iSoHienTai + "";
            btn_bep3.Text = ++iSoHienTai + "";
            btn_bep4.Text = ++iSoHienTai + "";
            btn_bep5.Text = ++iSoHienTai + "";
            btn_bep6.Text = ++iSoHienTai + "";

            
            //this.showData_BEP_MayIn_Loai();
            this.showData_BEP_MayIn();
        }
        #endregion

        #endregion

        #region "   Hoa Don"

        private void bton_dautrang_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtHEADER.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtHEADER.Text = s;
        }

        private void bton_cuoitrang_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtFOOTER.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtFOOTER.Text = s;
        }

        private void btnCanh_Tren_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Tren);
            omh_so.ShowDialog();
        }
        void Canh_Tren(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numMARIN_TOP.Value = dc;
                }
            }
        }

        private void btnCanh_Duoi_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Duoi);
            omh_so.ShowDialog();
        }
        void Canh_Duoi(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numMARIN_BOTTOM.Value = dc;
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //them
            this.ShowEdit_HoaDon("-1");
        }

        private void simpleButton8_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_HoaDon.GetDataRow(gridView_HoaDon.FocusedRowHandle);
            ma = dr["DM_MAYIN_HD_MA"] + "";

            if (ma != "")
            {
                if (new mh_thongbao("Bạn muốn xóa", 3).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_HD WHERE DM_MAYIN_HD_MA=" + ma;
                    int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });

                    this.showData_HoaDon_MayIn();
                }
            }
        }

        private void simpleButton7_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_HoaDon.GetDataRow(gridView_HoaDon.FocusedRowHandle);
            if (dr != null)
            {
                ma = dr["DM_MAYIN_HD_MA"] + "";
                this.ShowEdit_HoaDon(ma);
            }
        }

        private void btnThoat_HoaDon_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        void showData_HoaDon_MayIn()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_HD";

            DataTable tbInHoaDon = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControl_HoaDon.DataSource = tbInHoaDon.Copy();
        }

        void showData_HoaDon_CauHinh()
        {
            DataTable tbDM_MAYIN_HD_CAUHINH;
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_HD_CAUHINH";
            tbDM_MAYIN_HD_CAUHINH = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });

            if (tbDM_MAYIN_HD_CAUHINH.Rows.Count > 0)
            {
                txtLOGO_PATH.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["LOGO_PATH"] + "";
                check_inlogo.Checked = tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_LOGO"] + ""=="True";
                txtHEADER.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["HEADER"] + "";
                txtFOOTER.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["FOOTER"] + "";

                decimal dcMARIN_TOP = 0;
                decimal.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["MARIN_TOP"] + "", out dcMARIN_TOP);
                numMARIN_TOP.Value = dcMARIN_TOP;

                decimal dcMARIN_BOTTOM = 0;
                decimal.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["MARIN_BOTTOM"] + "", out dcMARIN_BOTTOM);
                numMARIN_BOTTOM.Value = dcMARIN_BOTTOM;

                //
                Boolean bchkPRINT_PRICE = true;
                Boolean bchkPRINT_STORE_NAME = true;

                Boolean bchkPRINT_RECEIPT_TITLE = true;
                Boolean bchkPRINT_PHONE_NUMBER = true;

                Boolean bchkPRINT_STORE_ADDRESS = true;
                Boolean bchkPRINT_ORDER_NO = true;

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_PRICE"] + "", out bchkPRINT_PRICE);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_STORE_NAME"] + "", out bchkPRINT_STORE_NAME);

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_RECEIPT_TITLE"] + "", out bchkPRINT_RECEIPT_TITLE);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_PHONE_NUMBER"] + "", out bchkPRINT_PHONE_NUMBER);

                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_STORE_ADDRESS"] + "", out bchkPRINT_STORE_ADDRESS);
                Boolean.TryParse(tbDM_MAYIN_HD_CAUHINH.Rows[0]["PRINT_ORDER_NO"] + "", out bchkPRINT_ORDER_NO);

                chkHD_PRINT_PRICE.Checked = bchkPRINT_PRICE;
                chkHD_PRINT_STORE_NAME.Checked = bchkPRINT_STORE_NAME;

                chkHD_PRINT_RECEIPT_TITLE.Checked = bchkPRINT_RECEIPT_TITLE;
                chkHD_PRINT_PHONE_NUMBER.Checked = bchkPRINT_PHONE_NUMBER;

                chkHD_PRINT_STORE_ADDRESS.Checked = bchkPRINT_STORE_ADDRESS;
                chkHD_PRINT_ORDER_NO.Checked = bchkPRINT_ORDER_NO;
                //
                txtTieuDe_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["TITLE"] + "";
                txtSoDienThoai_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["PHONE"] + "";
                txtDiaChi_HD.Text = tbDM_MAYIN_HD_CAUHINH.Rows[0]["ADDRESS"] + "";
                //panel_logo.BackgroundImage = new cpublic().ConvertByteArrayToImage(tbDM_MAYIN_HD_CAUHINH.Rows[0]["HINHLOGO"]);
                //string sLogoPath=Application.StartupPath+"/logo.bmp";
                //if (System.IO.File.Exists(sLogoPath))
                //{
                //    panel_logo.BackgroundImage = Image.FromFile(sLogoPath);
                //}
                //else
                //    panel_logo.BackgroundImage = null;
            }
            else
            {
                chkHD_PRINT_PRICE.Checked = true;
                chkHD_PRINT_STORE_NAME.Checked = true;

                chkHD_PRINT_RECEIPT_TITLE.Checked = true;
                chkHD_PRINT_PHONE_NUMBER.Checked = true;

                chkHD_PRINT_STORE_ADDRESS.Checked = true;
                chkHD_PRINT_ORDER_NO.Checked = true;
                //
                txtTieuDe_HD.Text = "";
                txtSoDienThoai_HD.Text = "";
                txtDiaChi_HD.Text = "";
            }
        }

        void ShowEdit_HoaDon(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_HoaDon, _ma);
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_HoaDon_MayIn();
        }

        private void btnLuu_HoaDon_Click(object sender, EventArgs e)
        {
            object oHinh = null;
            //if (pictureBox1.BackgroundImage != null)
            //    oHinh = new cpublic().ConvertImageToByteArray(ImageFormat.Gif, pictureBox1.BackgroundImage);

            int irt = 0;
            string sSQL = "UPDATE DM_MAYIN_HD_CAUHINH " +
                          "SET " +
                          "     LOGO_PATH = N'" + txtLOGO_PATH.Text.Trim() + "', " +
                          "     HEADER = N'" + txtHEADER.Text.Trim() + "', " +
                          "     FOOTER = N'" + txtFOOTER.Text.Trim() + "', " +
                          "     MARIN_TOP = " + numMARIN_TOP.Value + ", " +
                          "     MARIN_BOTTOM = " + numMARIN_BOTTOM.Value + ", " +
                          "     PRINT_PRICE = '" + chkHD_PRINT_PRICE.Checked + "', " +
                          "     PRINT_RECEIPT_TITLE = '" + chkHD_PRINT_RECEIPT_TITLE.Checked + "', " +
                          "     PRINT_PHONE_NUMBER = '" + chkHD_PRINT_PHONE_NUMBER.Checked + "', " +
                          "     PRINT_STORE_NAME = '" + chkHD_PRINT_STORE_NAME.Checked + "', " +
                          "     PRINT_STORE_ADDRESS = '" + chkHD_PRINT_STORE_ADDRESS.Checked + "', " +
                          "     PRINT_ORDER_NO = '" + chkHD_PRINT_ORDER_NO.Checked + "', " +
                          "     TITLE = N'" + txtTieuDe_HD.Text.Trim() + "', " +
                          "     [ADDRESS] = N'" + txtDiaChi_HD.Text + "', " +
                          "     PHONE = N'" + txtSoDienThoai_HD.Text + "', " +
                          "     HINHLOGO = '" + oHinh + "', " +
                          "     PRINT_LOGO = '" + check_inlogo.Checked + "' "
                          ;
            Image img = panel_logo.BackgroundImage;
            if (img != null)
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "logo.bmp"))
                    System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + "logo.bmp");
                img.Save(AppDomain.CurrentDomain.BaseDirectory + "logo.bmp");
            }
            irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                            new string[] { "@sSQL" }, new object[] { sSQL });
            if (irt >= 0)
                new mh_thongbao("Lưu thành công", 2).ShowDialog();

            
        }

        private void simpleButton17_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtTieuDe_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtTieuDe_HD.Text = s;
        }

        private void simpleButton13_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtDiaChi_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtDiaChi_HD.Text = s;
        }

        private void simpleButton12_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtSoDienThoai_HD.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtSoDienThoai_HD.Text = s;
        }

        #endregion

        #region "   Bien Nhan"

        private void bton_dautrang_BN_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtHEADER_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtHEADER_BN.Text = s;
        }

        private void bton_cuoitrang_BN_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtFOOTER_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtFOOTER_BN.Text = s;
        }

        private void btnCanh_Tren_BN_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Tren_BN);
            omh_so.ShowDialog();
        }
        void Canh_Tren_BN(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numBN_MARIN_TOP.Value = dc;
                }
            }
        }

        private void btnCanh_Duoi_BN_Click(object sender, EventArgs e)
        {
            Variable.pont_x = 300;
            Variable.pont_y = 300;
            mh_so omh_so = new mh_so();
            omh_so.eClick += new EventHandler(Canh_Duoi_BN);
            omh_so.ShowDialog();
        }
        void Canh_Duoi_BN(object sender, EventArgs e)
        {
            if (sender != null)
            {
                mh_so omh_so = (mh_so)sender;
                decimal dc = 0;
                if (omh_so.txt_ketqua.Text != "")
                {
                    decimal.TryParse(omh_so.txt_ketqua.Text, out dc);
                    numBN_MARIN_BOTTOM.Value = dc;
                }
            }
        }


        private void btnBN_Them_Click(object sender, EventArgs e)
        {
            //them
            this.ShowEdit_BIENNHAN("-1");
        }

        private void btnBN_Xoa_Click(object sender, EventArgs e)
        {
            //xoa
            string ma = "";
            DataRow dr = gridView_biennhan.GetDataRow(gridView_biennhan.FocusedRowHandle);
            ma = dr["DM_MAYIN_BIENNHAN_MA"] + "";

            if (ma != "")
            {
                if (new mh_thongbao("Bạn muốn xóa", 3).ShowForm() == DialogResult.OK)
                {
                    string sSQL = "DELETE FROM DM_MAYIN_BIENNHAN WHERE DM_MAYIN_BIENNHAN_MA=" + ma;
                    int irt = new thuvien().SP_Update("SP_EXECUTESQL",
                                                    new string[] { "@sSQL" }, new object[] { sSQL });

                    this.showData_BIENNHAN_MayIn();
                }
            }
        }

        private void btnBN_Sua_Click(object sender, EventArgs e)
        {
            //sua
            string ma = "";
            DataRow dr = gridView_biennhan.GetDataRow(gridView_biennhan.FocusedRowHandle);
            ma = dr["DM_MAYIN_BIENNHAN_MA"] + "";
            this.ShowEdit_BIENNHAN(ma);
        }

        private void btnThoat_BIENNHAN_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        void showData_BIENNHAN_MayIn()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BIENNHAN";

            DataTable tbInBN = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControl_BienNhan.DataSource = tbInBN.Copy();
        }
        void showData_BIENNHAN_CauHinh()
        {
            DataTable tbDM_MAYIN_BIENNHAN_CAUHINH;
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_MAYIN_BIENNHAN_CAUHINH";
            tbDM_MAYIN_BIENNHAN_CAUHINH = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });

            if (tbDM_MAYIN_BIENNHAN_CAUHINH.Rows.Count > 0)
            {
                txtLOGO_PATH_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["LOGO_PATH"] + "";
                txtHEADER_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["HEADER"] + "";
                txtFOOTER_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["FOOTER"] + "";

                decimal dcMARIN_TOP = 0;
                decimal.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["MARIN_TOP"] + "", out dcMARIN_TOP);
                numBN_MARIN_TOP.Value = dcMARIN_TOP;

                decimal dcMARIN_BOTTOM = 0;
                decimal.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["MARIN_BOTTOM"] + "", out dcMARIN_BOTTOM);
                numBN_MARIN_BOTTOM.Value = dcMARIN_BOTTOM;

                //
                Boolean bchkPRINT_PRICE = true;
                Boolean bchkPRINT_STORE_NAME = true;

                Boolean bchkPRINT_RECEIPT_TITLE = true;
                Boolean bchkPRINT_PHONE_NUMBER = true;

                Boolean bchkPRINT_STORE_ADDRESS = true;
                Boolean bchkPRINT_ORDER_NO = true;
                Boolean bPRINT_LOGO = true;
                

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_PRICE"] + "", out bchkPRINT_PRICE);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_STORE_NAME"] + "", out bchkPRINT_STORE_NAME);

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_RECEIPT_TITLE"] + "", out bchkPRINT_RECEIPT_TITLE);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_PHONE_NUMBER"] + "", out bchkPRINT_PHONE_NUMBER);

                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_STORE_ADDRESS"] + "", out bchkPRINT_STORE_ADDRESS);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_ORDER_NO"] + "", out bchkPRINT_ORDER_NO);
                Boolean.TryParse(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PRINT_LOGO"] + "", out bPRINT_LOGO);
                

                chkBN_PRINT_PRICE.Checked = bchkPRINT_PRICE;
                chkBN_PRINT_STORE_NAME.Checked = bchkPRINT_STORE_NAME;

                chkBN_PRINT_RECEIPT_TITLE.Checked = bchkPRINT_RECEIPT_TITLE;
                chkBN_PRINT_PHONE_NUMBER.Checked = bchkPRINT_PHONE_NUMBER;

                chkBN_PRINT_STORE_ADDRESS.Checked = bchkPRINT_STORE_ADDRESS;
                chkBN_PRINT_ORDER_NO.Checked = bchkPRINT_ORDER_NO;
                //
                txtTieuDe_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["TITLE"] + "";
                txtSoDienThoai_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["PHONE"] + "";
                txtDiaChi_BN.Text = tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["ADDRESS"] + "";

                //panel_logo_BN.BackgroundImage = new cpublic().ConvertByteArrayToImage(tbDM_MAYIN_BIENNHAN_CAUHINH.Rows[0]["HINHLOGO"]);
                //string sLogoPath = Application.StartupPath + "/logo1.bmp";
                //if (System.IO.File.Exists(sLogoPath))
                //    panel_logo_BN.BackgroundImage = Image.FromFile(sLogoPath).Clone();
                //else
                //    panel_logo_BN.BackgroundImage = null;

                check_inlogo_BN.Checked = bPRINT_LOGO;
            }
            else
            {
                chkBN_PRINT_PRICE.Checked = true;
                chkBN_PRINT_STORE_NAME.Checked = true;

                chkBN_PRINT_RECEIPT_TITLE.Checked = true;
                chkBN_PRINT_PHONE_NUMBER.Checked = true;

                chkBN_PRINT_STORE_ADDRESS.Checked = true;
                chkBN_PRINT_ORDER_NO.Checked = true;
                //
                txtDiaChi_BN.Text = "";
                txtTieuDe_BN.Text = "";
                txtSoDienThoai_BN.Text = "";

                panel_logo_BN.BackgroundImage = null;
                check_inlogo_BN.Checked = false;
            }
        }
        void ShowEdit_BIENNHAN(string _ma)
        {
            mh_dm_mayin_bep_info omh_dm_mayin_bep_info = new mh_dm_mayin_bep_info(mh_dm_mayin_bep_info.bang.DM_MAYIN_BienNhan, _ma);
            omh_dm_mayin_bep_info.ShowDialog();
            if (omh_dm_mayin_bep_info.DialogResult == DialogResult.OK)
                this.showData_BIENNHAN_MayIn();
        }

        private void btnLuu_BN_Click(object sender, EventArgs e)
        {
            object oHinh = null;
            //if (panel_logo_BN.BackgroundImage != null)
            //    oHinh = new cpublic().ConvertImageToByteArray(ImageFormat.Gif, panel_logo_BN.BackgroundImage);            
            
            int _iReasult = new thuvien().SP_Update("sp_DM_MAYIN_BIENNHAN_CAUHINH",
                       new string[] { "@flag", "@ADDRESS", "@DO_NOT_PRINT_ZERO_ITEM", 
                                            "@FOOTER", "@HEADER", "@HINHLOGO", 
                                            "@LOGO_PATH", "@MARIN_BOTTOM", "@MARIN_TOP", 

                                            "@OBJID", "@PHONE", "@PRINT_BILL_STAFF", 
                                            "@PRINT_BY_GROUP", "@PRINT_LOGO", "@PRINT_ORDER_NO", 

                                            "@PRINT_PHONE_NUMBER", "@PRINT_PRICE", "@PRINT_RECEIPT_TITLE", 
                                            "@PRINT_STORE_ADDRESS", "@PRINT_STORE_NAME", "@PRINT_TABLE_NO", 
                                            "@SELECT_PRINT", "@SUB_TOTAL_PRINT_DOWN", "@TAX_PRINT_BY_KIND", "@TITLE" },
                       new object[] { 1, txtDiaChi_BN.Text, null, 
                                            txtFOOTER_BN.Text.Trim() , txtHEADER_BN.Text.Trim(), oHinh, 
                                            txtLOGO_PATH_BN.Text, numBN_MARIN_BOTTOM.Value, numBN_MARIN_TOP.Value, 

                                            2011, txtSoDienThoai_BN.Text.Trim(), null, 
                                            null, check_inlogo_BN.Checked, chkBN_PRINT_ORDER_NO.Checked, 
                                            chkBN_PRINT_PHONE_NUMBER.Checked, chkBN_PRINT_PRICE.Checked, 

                                            chkBN_PRINT_RECEIPT_TITLE.Checked, chkBN_PRINT_STORE_ADDRESS.Checked, chkBN_PRINT_STORE_NAME.Checked, 
                                            null, null, null, 

                                            null, txtTieuDe_BN.Text });

            Image img = panel_logo_BN.BackgroundImage;
            if (img != null)
            {
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "logo1.bmp"))
                    System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + "logo1.bmp");
                img.Save(AppDomain.CurrentDomain.BaseDirectory + "logo1.bmp");
            }

            if (_iReasult >= 0)
                new mh_thongbao("Lưu thành công", 2).ShowDialog();
        }

        private void simpleButton16_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtTieuDe_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtTieuDe_BN.Text = s;
        }

        private void simpleButton15_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtDiaChi_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtDiaChi_BN.Text = s;
        }

        private void simpleButton14_Click(object sender, EventArgs e)
        {
            mh_chu omh_chu = new mh_chu();
            string s = omh_chu.ShowForm(txtSoDienThoai_BN.Text, 200, 200, false);
            if (omh_chu.DialogResult == DialogResult.OK)
                txtSoDienThoai_BN.Text = s;
        }
        #endregion

        private void btnLuuNhommayIn_Click(object sender, EventArgs e)
        {
            string sDM_MAYIN_BEP_MA = "";

            thuvien othuvien = new thuvien();
            string sSQL = "";
            if (btn_bep1.Tag + "" != "" && btn_bep1.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin1._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep1.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            if (btn_bep2.Tag + "" != "" && btn_bep2.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin2._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep2.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            if (btn_bep3.Tag + "" != "" && btn_bep3.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin3._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep3.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            if (btn_bep4.Tag + "" != "" && btn_bep4.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin4._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep4.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            if (btn_bep5.Tag + "" != "" && btn_bep5.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin5._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep5.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            if (btn_bep6.Tag + "" != "" && btn_bep6.Tag + "" != "0")
            {
                sSQL = "UPDATE DM_NHOMCHUHH SET DM_MAYIN_BEP_MA = '" + cbomayin6._GetselectedID() + "' WHERE OBJID LIKE '" + btn_bep6.Tag + "' ";
                othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            }

            //
            sSQL =  "DISABLE TRIGGER t_auto_mahanghoa ON dbo.DM_HH; "+
                    "UPDATE DM_HH SET DM_MAYIN_BEP_MA = NULL WHERE DM_MAYIN_BEP_MA NOT IN (SELECT DM_MAYIN_BEP_MA FROM DM_MAYIN_BEP); "+
                    "ENABLE TRIGGER t_auto_mahanghoa ON dbo.DM_HH; "
                ;
            othuvien.SP_Update("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            //
            MessageBox.Show("Lưu thành công");
        }

        private void btnCauHinh_Bep_Click(object sender, EventArgs e)
        {
            frmDM_MAYIN_BEP_CAUHINH ofrmDM_MAYIN_BEP_CAUHINH = new frmDM_MAYIN_BEP_CAUHINH();
            ofrmDM_MAYIN_BEP_CAUHINH.ShowDialog();
        }

        private void bton_logo_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "JPG Files(*.JPG)|*.JPG|GIF Files(*.GIF)|*.GIF|BMP Files(*.BMP)|*.BMP";
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                txtLOGO_PATH.Text = dlg.FileName;
                Image img = Image.FromFile(dlg.FileName);
                panel_logo.BackgroundImage = img;
            }
        }

        private void bton_logo_biennhan_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "JPG Files(*.JPG)|*.JPG|GIF Files(*.GIF)|*.GIF|BMP Files(*.BMP)|*.BMP";

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                txtLOGO_PATH_BN.Text = dlg.FileName;
                Image img = Image.FromFile(dlg.FileName);
                panel_logo_BN.BackgroundImage = img;

            }
        }

        private void panel_logo_Paint(object sender, PaintEventArgs e)
        {

        }

        private void gridControl_HoaDon_Click(object sender, EventArgs e)
        {

        }

        private void btnIn_Test_Click(object sender, EventArgs e)
        {
            string sfile = Application.StartupPath + "//LPV.PRINT_TEST.exe";
            if (System.IO.File.Exists(sfile))
                System.Diagnostics.Process.Start(sfile);
        }

      

        private void txtLOGO_PATH_Click(object sender, EventArgs e)
        {
            string sLogoPath = Application.StartupPath + "\\logo.bmp";
            if (System.IO.File.Exists(sLogoPath))
            {
                System.Diagnostics.Process.Start(sLogoPath,"Waiting...");
            }
        }

        private void txtLOGO_PATH_BN_Click(object sender, EventArgs e)
        {
            string sLogoPath = Application.StartupPath + "\\logo1.bmp";
            if (System.IO.File.Exists(sLogoPath))
            {
                System.Diagnostics.Process.Start(sLogoPath,"Waiting...");
            }
        }
    }
}
